<?php

namespace Rblog\Lib;

class Syscache {
    
    private $_m;
    
    public function __construct() {
        $this->_m = new \Rexzy\Tool\Memcache( \Rexzy::getConfig( 'memcache_host'), \Rexzy::getConfig( 'memcache_port') );
    }
    
    public function get( $key ) {
        $syscache = $this->_m->get( 'syscache' );
        if( ! $syscache ) {
            $data = \Rexzy::model( 'setup' )->selectAll( '*' );
            foreach( $data as $key1 => $val ) {
                $data[$val['keyword']] = $val['value'];
            }
            $this->_m->set( 'syscache', $data, 99999 );
        } else {
            $data = $syscache;
        }
        return $data[ $key ] ?: false;
    }
    
    /**
     * 删除
     * 
     * @param string $key 键名
     */
    public function delete( $key ) {
        $this->_m->delete( $key );
    }
}

